package org.helgoboss.document_database_orient_impl

import com.orientechnologies.orient.core.record.impl.ODocument
import org.helgoboss.document_database._

class OrientDocument(val bucket: OrientBucket, private[document_database_orient_impl] val delegate: ODocument) extends Document {
    def save {
        delegate.save
    }
    
    def keys = {
        import scala.collection.JavaConversions._
        delegate.fieldNames.toSet
    }
    
    def get[P](key: String) = {
        val value: Any = delegate.field(key)
        if (value == null) {
            None
        } else {
            Some(value.asInstanceOf[P])
        }
    }
    
    def apply(key: String) = {
        val value: Any = delegate.field(key)
        if (value == null) {
            None
        } else {
            Some(value)
        }
    }
    
    def update(key: String, value: Any) {
        delegate.field(key, value)
    }
    
    def remove(key: String) {
        delegate.removeField(key)
    }
}